#include "NormalMode.h"
#include "DotSceneLoader.h"

void NormalMode::Initialization()
{
	Scene::Initialization();
}

void NormalMode::createScene()
{
	_setFogSky();
	DotSceneLoader *loader = new DotSceneLoader();
	SceneNode *sceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BaseScene");
	loader->parseDotScene("SampleScene3.scene","Scene",mSceneMgr,sceneNode);
	sceneNode->scale(4,4,4);
	//sceneNode->scale(2,2,2);


	mCamera->setPosition(Ogre::Vector3(0,0,50));
	mCamera->lookAt(Ogre::Vector3(0,100,-100));	

	if(Kinect::getSingleton().isDown) {
		mWorld->RegisterController("Player",new PlayerKeyController(mSceneMgr));
	} else {
		mWorld->RegisterController("Player",new PlayerKinectController(mSceneMgr));
	}
	mWorld->RegisterController("Enemy",new EnemyController(mSceneMgr));
	mWorld->RegisterController("Robot",new RobotController(mSceneMgr));

	mWorld->RegisterController("Camera", new CameraController(mSceneMgr));

}

bool NormalMode::frameRenderingQueued( const Ogre::FrameEvent& evt )
{
	mWorld->AddTime(evt.timeSinceLastFrame);
	Scene::frameRenderingQueued(evt);
	return true;
}

void NormalMode::_setFogSky()
{
	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
	Ogre::Entity *ent;
	Ogre::Plane p;
	p.normal = Ogre::Vector3(0,1,0); 
	p.d = 0;
	Ogre::MeshManager::getSingleton().createPlane("FloorPlane", 
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
		p, 200000, 200000, 20, 20, true, 1, 9000, 9000, 
		Ogre::Vector3::UNIT_Z);
	// Create an entity (the floor)
	ent = mSceneMgr->createEntity("floor", "FloorPlane");
	ent->setMaterialName("Examples/BeachStones");
	Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	node->attachObject(ent);
	node->setPosition(0,0,0);
	//mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
	mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
	Ogre::Light* l = mSceneMgr->createLight("MainLight");
	l->setPosition(20,80,50);

	Ogre::ColourValue fadeColour(0.9, 0.9, 0.9);
	
	this->mViewport->setBackgroundColour(fadeColour);
	mSceneMgr->setFog(Ogre::FOG_EXP2, fadeColour, 0.003);
	mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8, 400);
}